package edu.tyut.game.ui.person

import android.content.Context
import android.content.Intent
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.widget.Toast
import androidx.lifecycle.ViewModelProvider
import edu.tyut.game.GameApplication
import edu.tyut.game.R
import edu.tyut.game.databinding.ActivityFeedackBinding
import edu.tyut.game.logic.model.Feedback
import edu.tyut.game.ui.learn.LearnViewModel
import edu.tyut.game.utils.LogUtils
import edu.tyut.game.utils.StatusBarUtils

class FeedbackActivity : AppCompatActivity() {

    private val tag = this::class.java.name

    private lateinit var binding: ActivityFeedackBinding

    private val viewModel by lazy {
        ViewModelProvider(this)[FeedbackViewModel::class.java]
    }

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)

        binding = ActivityFeedackBinding.inflate(layoutInflater)
        setContentView(binding.root)
        // 隐藏ActionBar
        // 状态栏透明
        StatusBarUtils.setTranslucentStatusBar(this)

        LogUtils.d(tag, GameApplication.loginUser.toString())
        viewModel.resData.observe(this){
            val res = it.getOrNull()
            LogUtils.d(tag, res ?: "res")
        }

        binding.submit.setOnClickListener {
            viewModel.sendFeedback(Feedback(0, GameApplication.loginUser?.id ?: 0,
                GameApplication.loginUser?.email ?: "2905154639@qq.com", binding.feedback.text.toString()))
            Toast.makeText(this, "非常感谢您的反馈！", Toast.LENGTH_LONG).show()
            binding.feedback.setText(resources.getString(R.string.feedback_success))
            binding.feedback.isActivated = false
            binding.feedback.isEnabled = false
        }

    }
    companion object{
        fun actionStart(context: Context){
            val intent = Intent(context, FeedbackActivity::class.java)
            context.startActivity(intent)
        }
    }
}